<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "t_course_schedule_resource".
 *
 * @property string $id
 * @property string $t_course_id
 * @property string $t_course_schedule_id
 * @property string $resource_id
 * @property string $file_id
 * @property string $type 预习 or 复习
 * @property string $item_id 章节id
 * @property string $times 预习为截止时间，复习为开始时间
 * @property string $create_by
 * @property string $create_time
 * @property string $update_by
 * @property string $update_time
 * @property int $del_flag
 *
 * @property TCourseSchedule $tCourseSchedule
 */
class TCourseScheduleResource extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 't_course_schedule_resource';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'required'],
            [['times', 'create_time', 'update_time'], 'safe'],
            [['del_flag'], 'integer'],
            [['id', 't_course_id', 't_course_schedule_id', 'resource_id', 'file_id', 'item_id', 'create_by', 'update_by'], 'string', 'max' => 36],
            [['type'], 'string', 'max' => 50],
            [['id'], 'unique'],
            [['t_course_schedule_id'], 'exist', 'skipOnError' => true, 'targetClass' => TCourseSchedule::className(), 'targetAttribute' => ['t_course_schedule_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            't_course_id' => 'T Course ID',
            't_course_schedule_id' => 'T Course Schedule ID',
            'resource_id' => 'Resource ID',
            'file_id' => 'File ID',
            'type' => 'Type',
            'item_id' => 'Item ID',
            'times' => 'Times',
            'create_by' => 'Create By',
            'create_time' => 'Create Time',
            'update_by' => 'Update By',
            'update_time' => 'Update Time',
            'del_flag' => 'Del Flag',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTCourseSchedule()
    {
        return $this->hasOne(TCourseSchedule::className(), ['id' => 't_course_schedule_id']);
    }
}
